/*
 * Copyright 2025 The Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *@file    : feature_matcher.h
 *@brief   : feature match 
 *@authors : zhanglei, zhanglei_723@126.com
 *@version : v1.0
 *@data    : 2025/8/30
 *
 */

#ifndef FEATURE_MATCHER_H
#define FEATURE_MATCHER_H

#include <Eigen/Eigen>
#include <iostream>
#include <unordered_map>
#include <vector>

#include "feature/feature_database.h"

namespace feature {

class FeatureMatcher {
public:
    FeatureMatcher(std::shared_ptr<FeatureDatabase> feature_database_ptr);
    void DescriptorMatch(uint64_t& feature_id, const uint8_t& camera_id, const uint64_t& frame_id, const uint64_t& last_frame_id, const std::vector<FeaturePoint>& feature_data);
private:
    inline double ComputeDescriptorDistance(const Vector128d &d1, const Vector128d &d2) {
        double distance = d1.dot(d2);
        distance = std::sqrt(2 - 2 * distance);
        return distance;
    }

    void FilterByFundamentalMatrix(std::vector<uchar>& inliers, const std::vector<Vector3d>& last_point, const std::vector<Vector3d>& curr_point);

    std::shared_ptr<FeatureDatabase> feature_database_ptr_;

    double window_size_; 
};

} // namespace feature

#endif /* FEATURE_MATCHER_H */